package com.youfan.book.controller;

import com.youfan.book.domain.Library;
import com.youfan.book.service.LibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("library")
@Controller
public class LibraryController {

    @Autowired
    private LibraryService libraryService;

    @GetMapping("library_modify")
    public String libraryModify(Model model) {
        Library library = libraryService.getById(1L);
        model.addAttribute("library", library);
        return "/library/library_modify";
    }

    @PostMapping("library_modify_do")
    public String libraryModifyDo(Library library) {
        libraryService.updateById(library);
        return "redirect:/library/library_modify";
    }

}
